package com.wc.alorithm_blue_bridge._动态规划.树形DP.左孩子右兄弟;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/1/10 20:47
 * @description
 * https://www.lanqiao.cn/problems/1451/learning/?contest_id=74
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] h = new int[N], e = new int[N], ne = new int[N];
    // f[i] 表示节点为 i 的最长子树
    static int[] f = new int[N];
    static int n, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 2; i <= n; i++) {
            int x = sc.nextInt();
            add(x, i);
        }
        dfs(1);
        out.println(f[1]);
        out.flush();
    }

    static int dfs(int x) {
        int res = 0, maxv = 0;
        for (int i = h[x]; i > 0; i = ne[i]) {
            int j = e[i];
            maxv = Math.max(maxv, dfs(j));
            res++;
        }

        return  f[x] = res + maxv;
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

